import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'
// import { Random } from 'mockjs'
// im:Random.image(),
const users=[{
	username:"123",
	password:"123",
	token:"token123"
}]
export function setupProdMockServer() {
    createProdMockServer([{
        url: "/api/getUsers",
        method: "get",
        response: () => {
			// throw new Error({code:444})
            return {
                code: 400,
                message: "ok",
                data: {
                    'rows|10': [{
                        id: '@guid',
                        name: '@cname',
                        'age|20-30': 23,
                        'job|1': ['前端工程师', '后端工程师', 'UI工程师', '需求工程师']
                    }]
                },
            }
        }
    },{
		url:"/api/login",
		method:"post",
		response:({
			body:{
				username,
				password
			}
		})=>{
			console.log("登录:",username,password);
			const user=users.find(item=>{
				if(item.username===username){
					return true
				}
			})
			if(user&&user.password===password){
				return {
					code:0,
					msg:"登录成功",
					token:user.token
				}
			}
			return {
				code:400,
				msg:"登录失败"
			}
		}
	}])
}